package com.damuzee.system.system.action;

import javax.annotation.Resource;

import org.mybatis.sql.condition.Criteria;
import org.mybatis.sql.page.Page;
import org.mybatis.sql.page.Pagination;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.damuzee.system.admin.domain.EmpUser;
import com.damuzee.system.admin.service.EmpUserService;

@Controller
public class AdminUserAction {

	@RequestMapping(value="/employee/list.do",method = RequestMethod.POST)
	@ResponseBody
	public Pagination<EmpUser>  list(Integer pageNum, Integer totalCount ,Integer pageSize ,
			String orderby, String order , ModelMap map){
		Page<EmpUser> page = new Page<EmpUser>();
		page.setCurrentPage(pageNum);
		if(totalCount != null){
			page.setTotal(totalCount);
		}
		page.setSize(pageSize);
		
		Criteria cri = new Criteria(EmpUser.class);
		
		if(orderby!= null && order != null ){
			cri.order(orderby, order);
		}
		page = userSerivce.getEmpUserList(page,cri);
	 	//page = userSerivce.getEmpUserList(page,user);
		
		return page.getPage();
	}
	
	@RequestMapping(value="/employee/list.do",method = RequestMethod.GET)
	public String list( ModelMap map ){
		Page<EmpUser> page = new Page<EmpUser>();
		//page.setCurrentPage(pageNum);
		//page.setTotal(totalCount);
		//page.setSize(20);
		
		Criteria cri = new Criteria(EmpUser.class);
		
		/*if(orderby!= null && order != null ){
			cri.order(orderby, order);
		}*/
		page = userSerivce.getEmpUserList(page,cri);
		map.put("page", page.getPage());
	 return "/employee/list" ;
		
	}
	
	@RequestMapping(value="/employee/add.do")
	public String add(){
		return  "/employee/add" ;
	}
	
	@RequestMapping(value="/employee/save.do")
	public String save(EmpUser empUser,String reUserPwd){
		/*userSerivce.saveUser(empUser);*/
		return "redirect:v_list.do" ;
	}
	
	
	@Resource
	private EmpUserService userSerivce ;
	
	
}
